package com.example.demo.Controller;

import com.example.demo.Mapper.My_assetMapper;
import com.example.demo.entity.ClientAsset;
import com.example.demo.entity.MyAssetInfo;
import com.example.demo.entity.VisuaInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;



@Controller
public class MyAssetController {
    @Autowired
    My_assetMapper my_assetMapper;

    @RequestMapping("/myasset")
    public String myCurr(Model model)  {
        String name = SecurityContextHolder.getContext().getAuthentication().getName();
        System.out.println(name);
        List<MyAssetInfo> results1 = my_assetMapper.getMyAsset(name);
        List<ClientAsset> results2 = my_assetMapper.getMyCurr(name);
        VisuaInfo results3 = my_assetMapper.visualData(name);
        System.out.println(results3);
        model.addAttribute("results1", results1);
        model.addAttribute("results2", results2);
        model.addAttribute("results3", results3);
        return "/common/MyAssetViewer.html";
    }

    @RequestMapping("/myasset_json")
    @ResponseBody
    public VisuaInfo get_myAsset(Model model)  {
        String name = SecurityContextHolder.getContext().getAuthentication().getName();
        VisuaInfo result = my_assetMapper.visualData(name);
        model.addAttribute("results3", result);
        return result;
    }

    /*@RequestMapping("/updateAsset")
    public String updateAsset(String id){
        my_assetMapper.updateAset(id);*/
   /* }*/

}






